//
//  AppTool.m
//  TextToImg
//
//  Created by Garenge on 2019/M/29.
//  Copyright © 2019 鹏鹏. All rights reserved.
//

#import "AppTool.h"
#import <SVProgressHUD/SVProgressHUD.h>

@implementation AppTool

singleton_implementation(AppTool)

static NSString *SPLITMODE = @"SPLITMODE";
- (SplitMode)getSpliteMode {
    NSInteger splitMode = [[NSUserDefaults standardUserDefaults] integerForKey:SPLITMODE];
    if (splitMode > 0) {
        return splitMode;
    } else {
        [self saveSplitMode:SplitModeWithString];
        return SplitModeWithString;
    }
}
- (BOOL)saveSplitMode:(SplitMode)splitMode {
    [[NSUserDefaults standardUserDefaults] setInteger:splitMode forKey:SPLITMODE];
    return [[NSUserDefaults standardUserDefaults] synchronize];
}
- (BOOL)clearSplitMode {
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:SPLITMODE];
    return [[NSUserDefaults standardUserDefaults] synchronize];
}

static NSString *SPLITTEXTCOUNT = @"SPLITTEXTCOUNT";
- (NSInteger)getSpliteTextCount {
    NSInteger splitTextCount = [[NSUserDefaults standardUserDefaults] integerForKey:SPLITTEXTCOUNT];
    if (splitTextCount >= 0) {
        return splitTextCount;
    } else {
        [self saveSplitTextCount:800];
        return 800;
    }
}
- (BOOL)saveSplitTextCount:(NSInteger)count {
    count = MAX(0, count);
    count = MIN(99999, count);
    [[NSUserDefaults standardUserDefaults] setInteger:count forKey:SPLITTEXTCOUNT];
    return [[NSUserDefaults standardUserDefaults] synchronize];
}

static NSString *SPLITSTRING = @"SPLITSTRING";
- (NSString *)getSplitString {
    NSString *splitString = [[NSUserDefaults standardUserDefaults] stringForKey:SPLITSTRING];
    if (nil == splitString) {
        splitString = @"====";
        [self saveSplitString:splitString];
    }
    return splitString;
}
- (BOOL)saveSplitString:(NSString *)string {
    [[NSUserDefaults standardUserDefaults] setValue:string forKey:SPLITSTRING];
    return [[NSUserDefaults standardUserDefaults] synchronize];
}

static NSString *CUSTOMSPLITE = @"CUSTOMSPLITE";
- (BOOL)getCustomSplite {
    BOOL customI = [[NSUserDefaults standardUserDefaults] boolForKey:CUSTOMSPLITE];
    return customI;
}
- (BOOL)saveCustomSplite:(BOOL)custom {
    [[NSUserDefaults standardUserDefaults] setBool:custom forKey:CUSTOMSPLITE];
    return [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (void)prepareData {
//    [SVProgressHUD setForegroundColor:[UIColor darkGrayColor]];
    [[AppTool sharedAppTool] getSpliteTextCount];
    [[AppTool sharedAppTool] saveCustomSplite:YES];
    [SVProgressHUD setMaximumDismissTimeInterval:1];
}

/// 全局字体
UIFont *APPUsualFontWithSize(CGFloat size) {
    return [UIFont fontWithName:@"STKaiti" size:size];
}

UIFont *APPUsualFontWithNameAndSize(NSString *fontName, CGFloat size) {
    return [UIFont fontWithName:fontName size:size];
}

@end
